<?php

class ReportAction extends CommonAction {

    function index(){
        
        $t_begin = I("tb",'');
        $t_stop = I("ts",'');
        if(empty($t_stop)){
            $t_stop = date("Y-m-d", time());
        }
        
        if(!empty($t_begin)){
            $this->assign("t_begin", $t_begin);
            $this->assign("t_stop", $t_stop);
            $members = A("Report", "Event")->getMembersByTime($t_begin, $t_stop);
            
        }else{
            $members = A("Report", "Event")->getMembersTableData();
        }

        //dump($members);
        $this->assign('members', $members);
        $this->display();
    }
    
    public function index_bak() {

        $t = I("t", "");
        if (!empty($t)) {
            $this->assign("t_date", $t);
            $members = A("Report", "Event")->getMembersByTime($t);
        } else {
            $members = A("Report", "Event")->getMembersTableData();
        }
        $this->assign('members', $members);
        $this->display();
    }

    public function detailInfo() {
        # code...
        $uid = I('uid', '0');
        //$t_date = I('t', '');
        
        $t_begin = I("tb",'');
        $t_stop = I("ts",'');
        if(empty($t_stop)){
            $t_stop = date("Y-m-d", time());
        }

        $real_name = D('Members')->where(array('id' => $uid))->getField('real_name');
        $total_learn_time = 0;
        
        $db_m_members_pdoc = M('MMembersPdoc');

        $details = M('Pdoc')->select();
        for ($i = 0; $i < count($details); $i++) {

            $map['uid'] = $uid;
            $map['pdoc_id'] = $details[$i]['pdoc_id'];
            
            
            if (!empty($t_begin)) {
                $map['start_time'] = array('egt', $t_begin);
                $map['stop_time'] = array('ELT', $t_stop." 99:99:99");
            }
            
            $details[$i]['time_study'] = $db_m_members_pdoc->where($map)->sum('time_study');
        
            if ($details[$i]['time_study']) {
                $total_learn_time += $details[$i]['time_study'];
            }
        }

        $this->assign("details", $details);
        $this->assign("username", $real_name);
        $this->assign("total_learn_time", $total_learn_time);
        //dump($details);
        $this->display();
    }
    
    public function detailInfo_bak() {
        # code...
        $uid = I('uid', '0');
        $t_date = I('t', '');

        $username = D('Members')->where(array('uid' => $uid))->getField('username');
        $total_learn_time = 0;

        $details = M('Pdoc')->select();
        for ($i = 0; $i < count($details); $i++) {

            $map['uid'] = $uid;
            if (!empty($t_date)) {
                $map['create_date'] = array('egt', $t_date);
            }
            $map['pdoc_id'] = $details[$i]['pdoc_id'];
            $res = M('MMembersPdoc')->where($map)->find();

            if ($res) {
                $details[$i]['create_date'] = $res['create_date'];
                $details[$i]['last_date'] = $res['last_date'];
                $details[$i]['time_study'] = $res['time_study'];
                $total_learn_time += $res['time_study'];
            }
        }

        $this->assign("details", $details);
        $this->assign("username", $username);
        $this->assign("total_learn_time", $total_learn_time);

        $this->display();
    }
    public function singleReportPage() {

        $this->display();
    }

    public function exportTotalExcel() {
        $t_begin = I("tb",'');
        $t_stop = I("ts",'');
        if(empty($t_stop)){
            $t_stop = date("Y-m-d", time());
        }

        A("Report", "Event")->exportTotalExcel($t_begin, $t_stop);
    }
    
    public function exportDetailExcel(){
        $t_begin = I("tb",'');
        $t_stop = I("ts",'');
        if(empty($t_stop)){
            $t_stop = date("Y-m-d", time());
        }

        A("Report", "Event")->exportDetailExcel($t_begin, $t_stop);
        //A("Report", "Event")->getMembersDetailTableData($t_begin, $t_stop);
    }

}

?>